package com.example.web;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import com.example.web.servlet.ComponentRegistrationServlet2;

@SpringBootApplication
/*
 * 	第一种方式注解扫描
 * 	使用注解的方式注册servlet需要在SpringbootHelloApplication.java中添加@ServletComponentScan注解
 */
@ServletComponentScan("com.example.web")
public class BootServletApplication {

	public static void main(String[] args) {
		SpringApplication.run(BootServletApplication.class, args);
	}

	/**
	 * 	第二种方式组件注册
	 * @return
	 */
	@Bean // 一定要加，不然这个方法不会运行
	public ServletRegistrationBean getServletRegistrationBean() { // 一定要返回ServletRegistrationBean
		ServletRegistrationBean bean = new ServletRegistrationBean(new ComponentRegistrationServlet2()); // 放入自己的Servlet对象实例
		bean.addUrlMappings("/hello2.do"); // 访问路径值
		return bean;
	}
}
